{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-12-28T09:13:59.630864100Z",
     "start_time": "2023-12-28T09:13:59.539450300Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import re\n",
    "df = pd.read_csv('../static/data/house_info.csv')\n",
    "df['title'] = df['title'].apply(lambda x:x.replace('\\n','').replace('\\r','').replace(' ',''))\n",
    "df['house_info'] = df['house_info'].apply(lambda x:x.replace('\\n','').replace('\\r','').replace(' ',''))\n",
    "df['address'] = df['house_info'].apply(lambda x:x.split('/')[0])\n",
    "df['address'] = df['address'].apply(lambda x:'无' if re.findall('仅剩\\d间',x) else x)\n",
    "df['area'] = df['house_info'].apply(lambda x:''.join(re.findall('/([\\-\\d\\.].*?)㎡/',x)))\n",
    "df['area'] = df['area'].apply(lambda x: '0' if x==''else x) \n",
    "df['area'] = df['area'].apply(lambda x:round(sum([float(i) for i in x.split('-')])/len(x.split('-'))))\n",
    "df['house_type'] = df['house_info'].apply(lambda x:''.join(re.findall('/(\\d室\\d厅\\d卫)/',x)))\n",
    "df['house_type'] = df['house_type'].apply(lambda x:'无' if x=='' else x)\n",
    "df['face'] = df['house_info'].apply(lambda x:''.join(re.findall('/([东南西北]{1,2})/',x)))\n",
    "df['face'] = df['face'].apply(lambda x:'无' if x=='' else x)\n",
    "df['floor'] = df['house_info'].apply(lambda x:''.join(re.findall('[高中低]楼层',x)))\n",
    "df['floor'] = df['floor'].apply(lambda x:'无' if x=='' else x)\n",
    "df['price'] = df['price'].apply(lambda x:x.split(' ')[0])\n",
    "df['price'] = df['price'].apply(lambda x:round(sum([float(i) for i in x.split('-')])/len(x.split('-'))))\n",
    "df_new = df[['title','address','area','house_type','face','floor','price','tags']]\n",
    "df_new.to_csv('../static/data/house_info_pre.csv',index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
